import { ElMessage } from "element-plus";
import Typings from "../typings";

/**
 * 消息提示队列
 * ElMessage 自动关闭前的时间内，重复的错误提示只显示一次
 */
let msgArr: string[] = [];

export const $singleMsg: (options: Typings.Message.option) => void = (
  options = {
    type: "success",
    message: "消息",
  }
) => {
  if (!msgArr.some((item) => item === options.message)) {
    msgArr.push(options.message);
    ElMessage({
      ...options,
      onClose: () => {
        msgArr = msgArr.filter((item: string) => item !== options.message);
      },
    });
  }
};
